package com.lychee.moli.controller;

import com.lychee.moli.entity.BaseResultEntity;
import com.lychee.moli.entity.ProductEntity;
import com.lychee.moli.service.IProductService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by Lychee on 2018/4/10 15:48.
 * <p>
 * Author:Hejingzhou
 * <p>
 * Email:tcowork@163.com
 */
@RequestMapping(value = "/Product")
@Controller
public class ProductController {

    private Logger logger = Logger.getLogger(ProductController.class);

    @Resource
    private IProductService productService;

    /**
     * 获取商品列表
     *
     * @return
     */
    @RequestMapping(value = "/showAllProduct")
    @ResponseBody
    public BaseResultEntity<List<ProductEntity>> showAllProduct(HttpServletRequest request) {
        String userID = (String) request.getAttribute("UserID");
        logger.info("需要身份信息UserId\t" + userID);
        List<ProductEntity> productEntities = productService.showAllProduct();
        for (ProductEntity productEntity : productEntities) {
            logger.info(productEntity.toString());
        }
        return new BaseResultEntity<List<ProductEntity>>(BaseResultEntity.ERROR_CODE_SUCCESS, productEntities, "请求成功");
    }
}
